package br.com.vti.sisp_sicrim.antigo.util;

import java.io.Serializable;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpSession;

import br.com.caelum.vraptor.ioc.Component;
import br.com.caelum.vraptor.ioc.SessionScoped;
import br.com.vti.sisp_sicrim.antigo.model.Usuario;

/**
 * 
 * Classe com atributos da sess�o do usu�rio
 * 
 * @author Incode
 * 
 */
@Component
@SessionScoped
public class Sessao implements Serializable {

	private ServletContext servletContext;
	private HttpSession httpSession;
	private Sisgsisp sisgsisp;
	private Scrg001 scrg001;
	private Usuario usuario;

	public ServletContext getServletContext() {
		return servletContext;
	}

	public void setServletContext(ServletContext servletContext) {
		this.servletContext = servletContext;
	}

	public HttpSession getHttpSession() {
		return httpSession;
	}

	public void setHttpSession(HttpSession httpSession) {
		this.httpSession = httpSession;
	}

	public void setAtributo(String chave, Object valor) {
		httpSession.setAttribute(chave, valor);
	}

	public Object getAtributo(String chave) {
		return httpSession.getAttribute(chave);
	}

	public Sisgsisp getSisgsisp() {
		if (sisgsisp == null)
			sisgsisp = new Sisgsisp();
		return sisgsisp;
	}

	public void setSisgsisp(Sisgsisp sisgsisp) {

		this.sisgsisp = sisgsisp;
	}

	public Scrg001 getScrg001() {
		return scrg001;
	}

	public void setScrg001(Scrg001 scrg001) {
		this.scrg001 = scrg001;
	}

	public boolean isAtiva() {
		return usuario != null;
	}

	public String getUser() {
		return usuario.getUser();
	}

	public String getInitUser() {
		return usuario.getInitUser();
	}

	public void sair() {
		usuario = null;
		httpSession.invalidate();
	}

	public void setUsuario(Usuario usuario) {

		this.usuario = usuario;
	}

	public Usuario getUsuario() {
		return usuario;
	}
}
